<?php
	/**
	*Author 雷日锦 362606856@qq.com 
	*控制器自动生成
	*/
	if(!defined("ROOT_PATH")) exit("die Access ");
	class cyitem_joinControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
			$this->loadConfig("table");
		}
		
		public function onDefault(){
			$where=" siteid=".SITEID." AND status<10 ";
			$url=APPADMIN."?m=cyitem_join&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("cyitem_join")->select($option,$rscount);
			if($data){
				foreach($data as $v){
					$uids[]=$v['userid'];
					$cyids[]=$v['cyid'];
				}
				$us=M("user")->getUserByIds($uids);
				$cys=M("cyitem")->getListByIds($cyids);
				foreach($data as $k=>$v){
					$u=$us[$v['userid']];
					$v['cyitem']=$cys[$v['cyid']];
					$v['user_head']=$u['user_head'];
					$data[$k]=$v;
				}
			}
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url,
					"status_list"=>$this->config_item('status_list'),
				)
			);
			$this->smarty->display("cyitem_join/index.html");
		}
		
		public function onAdd(){
			$id=get_post("id","i");
			if($id){
				$data=M("cyitem_join")->selectRow(array("where"=>"id=".$id));
				if($data){
					$cyitem=M("cyitem")->selectRow(array("where"=>"id=".$data['cyid']));
				}
			}
			$this->smarty->assign(array(
				"data"=>$data,
				"cyitem"=>$cyitem,
				"status_list"=>$this->config_item('status_list'),
			));
			$this->smarty->display("cyitem_join/add.html");
		}
		
		public function onSave(){
			$id=get_post("id","i");
			$data=M("cyitem_join")->postData();
			if($id){
				M("cyitem_join")->update($data,"id='$id'");
			}else{
				M("cyitem_join")->insert($data);
			}
			$this->goall("保存成功");
		}
		
		public function onStatus(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			M("cyitem_join")->update(array("status"=>$status),"id=$id");
			$this->goall("状态修改成功",0);
		}
		
		public function onDelete(){
			$id=get_post('id',"i");
			M("cyitem_join")->delete("id=".$id);
			$this->goall("删除成功",0);
		}
		
		
	}

?>